<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">开始日期</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="startDate" lay-verify="required" placeholder="请选择开始日期">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">结束日期</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="endDate" lay-verify="required" placeholder="请选择结束日期">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" >证券账户</label>
                            <div class="layui-input-inline">
                                <select name="modules" lay-verify="required" lay-search="" id="secu">
                                    <option value="">请选择证券账户</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script src="/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/static/js/jquery-3.4.1.min.js" charset="UTF-8"></script>
<script src="/static/js/table.js" charset="UTF-8"></script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //常规用法
        laydate.render({
            elem: '#startDate',
            value: new Date().toISOString().substring(0,10)
        });

        laydate.render({
            elem: '#endDate',
            value: new Date().toISOString().substring(0,10)
        });
    });

    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/transaction/search',
            parseData: function(result){ //result为后端返回的数据
                return {
                    "code": result.code,
                    "msg": result.msg,
                    "count": result.count,
                    "data": result.data
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            cols: [[
                {field: 'tNumber', align: 'center',width: 110, title: '交易编号', sort: true},
                {field: 'tDirection', align: 'center',width: 100, title: '交易方向'},
                {field: 'dealDate', align: 'center',width: 110, title: '交易日期', sort: true},
                {field: 'mType', align: 'center',width: 100, title: '交易市场'},
                {field: 'iCode', align: 'center',width: 110, title: '债券代码', sort: true},
                {field: 'iName', align: 'center',width: 110, title: '债券名称', sort: true},
                {field: 'dealPaySum', align: 'center',width: 140, title: '成交金额(万)', sort: true},
                {field: 'couponAmount', align: 'center',width: 140, title: '卷面金额(万)', sort: true},
                {field: 'dealAvgPrice', align: 'center',width: 140, title: '成交均价(万)', sort: true},
                {field: 'charge', align: 'center',width: 140, title: '交易费用(万)', sort: true},
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            size: "sm"
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function () {
            let startDate = $("#startDate");
            let endDate = $("#endDate");
            let secuCode = $("#secu");
            if (startDate.val() > endDate.val()) {
                layer.msg('开始日期不能大于结束日期');
                startDate.val("");
                endDate.val("");
                return false;
            }
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    secuCode:secuCode.val(),
                    startDate:startDate.val(),
                    endDate:endDate.val(),
                }
            });

            return false;
        });
    });

</script>

</body>
</html>